package com.yanqu.road.entity.estatewar;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserPatrons;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class UserEstateFloor {

	private int type;

	private int pos;

	private long userId;

	private long joinTime;

	private UserBaseInfo userBaseInfo = new UserBaseInfo();

	private BigInteger totalAbility = BigInteger.ZERO;

	private List<UserPatrons> patronsList = new ArrayList<>();

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getPos() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public long getJoinTime() {
		return joinTime;
	}

	public void setJoinTime(long joinTime) {
		this.joinTime = joinTime;
	}

	public BigInteger getTotalAbility() {
		return totalAbility;
	}

	public void setTotalAbility(BigInteger totalAbility) {
		this.totalAbility = totalAbility;
	}

	public List<UserPatrons> getPatronsList() {
		return patronsList;
	}

	public void setPatronsList(List<UserPatrons> patronsList) {
		this.patronsList = patronsList;
	}

	public UserPatrons getPatrons(int patronsId){
		for(UserPatrons userPatrons : patronsList){
			if(userPatrons.getPatronsId() == patronsId){
				return userPatrons;
			}
		}
		return null;
	}

	public boolean isContainsPatrons(int patronsId){
		UserPatrons userPatrons = getPatrons(patronsId);
		return null != userPatrons;
	}

	public void addPatrons(UserPatrons userPatrons){
		replacePatrons(userPatrons);
	}

	public void replacePatrons(UserPatrons userPatrons){
		UserPatrons oldPatrons = getPatrons(userPatrons.getPatronsId());
		if(null != oldPatrons){
			patronsList.remove(oldPatrons);
		}
		patronsList.add(userPatrons);
	}

	public UserBaseInfo getUserBaseInfo() {
		return userBaseInfo;
	}

	public String getUserBaseInfoJsonStr(){
		if(null == userBaseInfo){
			return "{}";
		}else {
			return JSON.toJSONString(userBaseInfo);
		}
	}

	public void setUserBaseInfo(UserBaseInfo userBaseInfo) {
		this.userBaseInfo = userBaseInfo;
	}

	public UserEstateFloor clone(){
		UserEstateFloor cloneFloor = new UserEstateFloor();
		cloneFloor.setType(type);
		cloneFloor.setPos(pos);
		cloneFloor.setUserId(userId);
		cloneFloor.setJoinTime(joinTime);
		cloneFloor.setTotalAbility(totalAbility);
		return cloneFloor;
	}
}
